<template>
  <section class="home">
    <div class="block">
      <el-carousel height="33vw" @change="resetScaleFactor">
        <el-carousel-item v-for="(item, index) in imgList" :key="index">
          <img :src="item" class="image" :style="{ transform: `scale(${scaleFactor})` }">
          <h3 class="small">{{ item }}</h3>
        </el-carousel-item>
      </el-carousel>
    </div>
  </section>
</template>

<script>
import carouselOne from "@/assets/image/发展共赢.png";
import carouselTwo from "@/assets/image/二十大.png";
import carouselThree from "@/assets/image/山西工学院.png";
import carouselFour from "@/assets/image/新思想.png";

export default {
  name: "carousel",
  data() {
    return {
      imgList: [
        new URL("@/assets/image/二十大.png", import.meta.url).href,
        new URL("@/assets/image/发展共赢.png", import.meta.url).href,
        new URL("@/assets/image/新思想.png", import.meta.url).href,
        new URL("@/assets/image/共建.png", import.meta.url).href,
      ],
      scaleFactor: 1, // 图片放大倍数
    };
  },
  methods: {
    resetScaleFactor() {
      this.scaleFactor = 1; // 切换图片时重置 scaleFactor
    },
  },
  // mounted() {
  //   // 在 mounted 钩子中，每隔一段时间增加 scaleFactor，实现图片慢慢变大的效果
  //   setInterval(() => {
  //     this.scaleFactor += 0.001;
  //   }, 10);
  // },
};
</script>

<style lang="scss" scoped>
.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n+1) {
  background-color: #d3dce6;
}

img {
  /*设置图片宽度和浏览器宽度一致*/
  width: 100%;
  height: inherit;
  transition: transform 0.5s ease; // 添加变换动画效果
}
</style>
